﻿namespace _1137第N个斐波那契数
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Solution solution = new Solution();
            Console.WriteLine(solution.Tribonacci(5));  
        }
    }
    public class Solution
    {
        public int Tribonacci(int n)
        {
            if (n == 0) return 0;
            if (n == 1) return 1;
            if (n == 2) return 1;
            if (n == 3) return 2;
            int p = 0, q = 1, t = 1, r = 2;
            for (int i = 4; i <= n; ++i)
            {
                p = q;
                q = t;
                t = r;
                r = p + q + t;
            }
            return r;
        }
    }
}